package com.example.service;

import com.example.model.UserDto;
import com.example.third.LunaRemoteClient;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.rest.client.inject.RestClient;

@Slf4j
@ApplicationScoped
public class LunaRemoteService {

    /**
     * 注入远程调用client，处理使用注解@Inject，还要使用@RestClient
     */
    @Inject
    @RestClient
    LunaRemoteClient lunaRemoteClient;
    @Inject
    ObjectMapper objectMapper;

    public UserDto requestLuan(String name) throws JsonProcessingException {
        UserDto userDto = new UserDto();
        userDto.setName(name);
        userDto.setAge(18);

        UserDto body = lunaRemoteClient.body(userDto);
        log.info("body: {}", objectMapper.writeValueAsString(body));
        return body;
    }
}
